package com.structure.algorithm;

/**
 *
 * Created by sucre on 2015/12/1.
 */
public class MergeSortedArray2 {
    /**
     *  @param A: sorted integer array A which has m elements,
     *           but size of A is m+n
     * @param B: sorted integer array B which has n elements
     */
    public void mergeSortedArray(int[] A, int m, int[] B, int n) {
        // write your code here
        int merge = m +n-1;
        int i = m -1;
        int j = n -1;
        while(j>=0){
            if(i>=0 && A[i] > B[j]){
                A[merge--]=A[i--];
            }else{
                A[merge--]=B[j--];
            }
        }
    }
}
